package org.wms.minbearwcs.serivce.mission.generate;

import lombok.Getter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.wms.minbearwcs.serivce.mission.generate.type.MissionGenType;

import java.util.HashMap;
import java.util.Map;


@Component
public class MissionGeneratorCollector implements ApplicationContextAware {

    private final Map<MissionGenType,MissionGenerator> collector = new HashMap<>();

    public MissionGenerator getGenerator(MissionGenType missionGenType){
        return collector.get(missionGenType);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        String[] names = applicationContext.getBeanNamesForType(MissionGenerator.class);
        for (String name : names) {
            MissionGenerator bean = (MissionGenerator) applicationContext.getBean(name);
            collector.put(bean.type(),bean);
        }
    }
}
